﻿<UserControl
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:SampleData="clr-namespace:Expression.Blend.SampleData.RevisionHistoryViewModelSampleDataSource"
             xmlns:local="clr-namespace:AttachedCommandBehavior;assembly=Infrastructure"
             xmlns:Behaviors="clr-namespace:Infrastructure.Behaviors;assembly=Infrastructure"
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
             x:Class="SourceControlMonitor.Views.RevisionHistoryView" 
             mc:Ignorable="d"
             d:DesignHeight="550" d:DesignWidth="800">
    <UserControl.Resources>
        <ResourceDictionary>
            <SampleData:RevisionHistoryViewModelSampleDataSource x:Key="RevisionHistoryViewModelSampleDataSource" d:IsDataSource="True"/>
            <Style TargetType="{x:Type DataGrid}">
                <Setter Property="HorizontalAlignment" Value="Stretch" />
                <Setter Property="VerticalAlignment" Value="Stretch" />
                <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                <Setter Property="VerticalContentAlignment" Value="Stretch" />
            </Style>
        </ResourceDictionary>
    </UserControl.Resources>
    <Grid d:DataContext="{Binding Source={StaticResource RevisionHistoryViewModelSampleDataSource}}">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <TextBlock HorizontalAlignment="Right" Text="{Binding CurrentRepository.Status}" FontWeight="Bold" Margin="0,0,30,0" />
        <ScrollViewer Grid.Row="1" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Disabled">
            <DataGrid x:Name="dataGrid" ItemsSource="{Binding CurrentRepository.CommitItems}" 
                  IsReadOnly="True" AutoGenerateColumns="False" RowDetailsVisibilityMode="VisibleWhenSelected" VerticalGridLinesBrush="Transparent" >
                <DataGrid.AlternatingRowBackground>
                    <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                        <GradientStop Color="White"/>
                        <GradientStop Color="#FFEDF3F9" Offset="1"/>
                    </LinearGradientBrush>
                </DataGrid.AlternatingRowBackground>
                <DataGrid.RowDetailsTemplate>
                    <DataTemplate>
                        <ListBox ItemsSource="{Binding ItemChanges}">
                            <ListBox.ItemTemplate>
                                <DataTemplate>
                                    <Grid local:CommandBehavior.Event="MouseDown" local:CommandBehavior.Command="{Binding OnViewChanges}">
                                        <Grid.ColumnDefinitions>
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition Width="Auto" />
                                            <ColumnDefinition />
                                        </Grid.ColumnDefinitions>
                                        <!-- TODO: implement -->
                                        <!--<CheckBox IsHitTestVisible="False" IsChecked="{Binding HasLocalEdits}" />-->
                                        <TextBlock Text="{Binding ChangeType}" Padding="10,0,10,0" Grid.Column="1"/>
                                        <TextBlock Text="{Binding FilePath}" Grid.Column="2" />
                                    </Grid>
                                </DataTemplate>
                            </ListBox.ItemTemplate>
                            <i:Interaction.Behaviors>
                                <Behaviors:IgnoreMouseWheelBehavior />
                            </i:Interaction.Behaviors>
                        </ListBox>
                    </DataTemplate>
                </DataGrid.RowDetailsTemplate>
                <DataGrid.Columns>
                    <!-- TODO: implement-->
                    <!--<DataGridCheckBoxColumn Header="Possible conflict?" Binding="{Binding HasLocalEditsOnAnyFile}" />-->
                    <DataGridTextColumn SortDirection="Descending" Header="Revision" Binding="{Binding Revision}" />
                    <DataGridTextColumn Header="Author" Binding="{Binding Author}" />
                    <DataGridTextColumn Header="Date" Binding="{Binding Date, StringFormat={}{0:MM/dd/yyyy hh:mm tt}}" />
                    <DataGridTextColumn Header="Commit Message" Width="*" Binding="{Binding LogMessage}" FontWeight="Bold" />
                </DataGrid.Columns>
            </DataGrid>
        </ScrollViewer>
    </Grid>
</UserControl>
